#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>

#include "tcs_sm.h"
#include "tcs_constant.h"
#include "crypto/sm/sm3.h"
#include "crypto/sm/sm2_if.h"
#include "debug.h"

#define SM2_PUBLIC_KEY_SIZE 64
#define DEFAULT_HASH_SIZE 32
#define DEFAULT_SIGN_SIZE 64

static void usage()
{
    printf("\n"
           " Usage: ./sm2_verify_b #for pantum\n");
}

int main(int argc, char **argv)
{
    int ret = 0;
    int ch = 0;

    uint8_t pubkey[SM2_PUBLIC_KEY_SIZE] = {
	0x2F, 0x86, 0x7A, 0x9C, 0xB5, 0x96, 0x76, 0xFB, 0xD2, 0x02, 0xC0, 0x3C,
	0x0C, 0xD6, 0xF7, 0x82, 0x51, 0xC3, 0xD9, 0xA9, 0xA1, 0x23, 0x8A, 0xF2,
	0x4C, 0x75, 0x52, 0xBE, 0xE8, 0xE6, 0x00, 0x08, 0xA4, 0xB9, 0x8C, 0xE6,
	0xD0, 0x45, 0x04, 0x52, 0x7E, 0x3B, 0x30, 0x58, 0xBF, 0x03, 0xDD, 0x6B,
	0x7C, 0x98, 0xF1, 0xA4, 0xC8, 0x50, 0xCB, 0x9E, 0x78, 0xC7, 0x75, 0x31,
	0xB3, 0x8A, 0xB1, 0xB1
    };


    uint8_t digest[DEFAULT_HASH_SIZE] = {
    0xA6, 0x1B, 0x02, 0xA4, 0x5F, 0x03, 0x54, 0x99, 0xFB, 0x62, 0xD1, 0x24,
	0xFA, 0xA6, 0xCB, 0xCD, 0xC9, 0x92, 0xAB, 0x6B, 0xE2, 0x84, 0x63, 0x8B,
	0x3B, 0xFD, 0x57, 0xF4, 0x92, 0x61, 0xF9, 0xEE
    };
    uint8_t sig[DEFAULT_SIGN_SIZE] = {
	0x41, 0x86, 0xB0, 0xE0, 0xC8, 0x5B, 0x93, 0x4C, 0xBD, 0xF5, 0xF5, 0x23,
	0x93, 0xF5, 0xF8, 0xE8, 0x6C, 0xAE, 0xF1, 0xA5, 0x50, 0x91, 0x74, 0x85,
	0xA1, 0x3D, 0x00, 0xDD, 0x0F, 0x5E, 0x79, 0xF4, 0x24, 0xC0, 0x6D, 0x2B,
	0xDA, 0xCE, 0x7C, 0x9B, 0xD4, 0x0D, 0x59, 0x5A, 0xFA, 0xE6, 0x36, 0x5F,
	0x16, 0xB1, 0x98, 0xBD, 0x0F, 0x02, 0x7B, 0x44, 0x77, 0xFF, 0xB0, 0x5B,
	0x20, 0x94, 0xB4, 0x61
    };


    uint32_t publen = sizeof(pubkey);  
    uint32_t sigLen = sizeof(sig);
    uint32_t digest_len = sizeof(digest);

    

    while ((ch = getopt(argc, argv, "h")) != -1)
    {
        switch (ch)
        {
        case 'h':
            usage();
            return 0;
        }
    }

   
    /** Check whether sign|verify is correct */
    if (0 != tcs_sm2_verify_b(pubkey, publen, digest, digest_len, sig, sigLen))
    {
        printf("openssl SM2 Verify failed\n");
        return -1;
    }
    printf("openssl SM2 Verify OK\n");
    return ret;
}


